<script setup>
import { Edit, Delete, Refresh } from '@element-plus/icons-vue'
import { onMounted, ref } from 'vue'
import { artGetChannelsService, artDelChannelService } from '@/api/article'
import ChannelEdit from './components/ChannelEdit.vue'
const channelList = ref([


])

onMounted(() => {
  getChannelList()
})
const getChannelList = async () => {
  loading.value = true
  const res = await artGetChannelsService()
  channelList.value = res.data.data
  console.log(channelList.value)
  loading.value = false
}
const onDelChannel = async (row) => {
  await ElMessageBox.confirm('你确认删除该分类信息吗？', '温馨提示', {
    type: 'warning',
    confirmButtonText: '确认',
    cancelButtonText: '取消'
  })
  await artDelChannelService(row.id)
  ElMessage({ type: 'success', message: '删除成功' })
  getChannelList()
}
const loading = ref(false)
const dialogVisible = ref(false)
// const onEditChannel = (row) => {
//   console.log(row)
// }
// const onAddChannel = () => {
//   dialogVisible.value = true
// }
const dialog = ref()
const onEditChannel = (row) => {
  dialog.value.open(row)
}

const onAddChannel = () => {
  dialog.value.open({})
}
const onSuccess = () => {
  getChannelList()
}
const refresh = () => {
  getChannelList()
  ElMessage.success('刷新成功')
}
</script>
<template>
  <page-container title="文章分类">
    <template #extra>
      <el-button type="primary" @click="onAddChannel"> 添加分类 </el-button>
      <el-button type="primary" @click="refresh" :icon="Refresh"> 刷新 </el-button>
    </template>

    <el-table v-loading="loading" :data="channelList" style="width: 100%">
      <el-table-column label="序号" width="100" type="index"> </el-table-column>
      <el-table-column label="分类名称" prop="cateName"></el-table-column>
      <el-table-column label="分类别名" prop="cateAlias"></el-table-column>
      <el-table-column label="操作" width="100">
        <template #default="{ row }">
          <el-button :icon="Edit" circle plain type="primary" @click="onEditChannel(row)"></el-button>
          <el-button :icon="Delete" circle plain type="danger" @click="onDelChannel(row)"></el-button>
        </template>
      </el-table-column>
      <template #empty>
        <el-empty description="没有数据" />
      </template>
    </el-table>
    <el-dialog v-model="dialogVisible" title="添加弹层" width="30%">
      <div>我是内容部分</div>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="dialogVisible = false">取消</el-button>
          <el-button type="primary"> 确认 </el-button>
        </span>
      </template>
    </el-dialog>
    <ChannelEdit ref="dialog" @success="onSuccess"></ChannelEdit>

  </page-container>

</template>


<style lang="scss" scoped></style>
